#!/usr/bin/env python
# -*- coding:utf-8 -*-
# __author__ = "tingfeng"
# Date: 2020/4/29
import random
import re
import pymysql
from appium.webdriver.common.touch_action import TouchAction
import time
from page.login_page import LoginPage


class LoginHandle:
    def __init__(self, i, ):
        self.login_page = LoginPage(i)

    def Save_ScreenShot(self,x):
        return self.login_page.Save_ScreenShot(x)

    def sendPassword(self):
        '''
        输入密码
        :return:
        '''
        return self.login_page.get_password_element().send_keys("00000000")

    def click_loginButton(self):
        '''
        点击登录
        :return:
        '''
        return self.login_page.get_loginButton_element().click()

    def click_backtwo(self):
        '''
        返回
        :return:
        '''
        return self.login_page.backC_two()

    def click_backone(self):
        return self.login_page.backC_one()

    def swipe_downC(self):
        time.sleep(2)
        return self.login_page.Swipe_DownC(1000)

    def swipe_upC(self):
        time.sleep(2)
        return self.login_page.Swipe_UpC(1000)

    def swipe_leftC(self):
        time.sleep(2)
        return self.login_page.Swip_LeftC(1000)

    def swipe_leftCYQ(self):
        time.sleep(2)
        return self.login_page.Swip_LeftCYQC(1000)

    def swipe_leftBD(self):
        time.sleep(2)
        return self.login_page.Swip_LeftBDC(1000)

    def swipe_rightC(self):
        time.sleep(2)
        return self.login_page.Swip_RightC(1000)

    def swipe_rightCYQ(self):
        time.sleep(2)
        return self.login_page.Swip_RightCYQC(1000)

    def scroll_page_washlist(self):
        return self.login_page.scroll_washlist()

    def switch_FindElements(self,q):
        '''
        判断页面元素是否存在
        '''
        if self.login_page.is_element_exist(q):
            return True
        else:
            return False

    def print_elements(self, i):
        '''

        :return:
        '''
        elements = self.login_page.get_element_textC()
        return elements[i].text

    def click_elements(self, j):
        '''
        获取要点击的元素
        :param j:
        :return:
        '''
        element = self.login_page.get_element_textC()
        return element[j].click()

    def click_view(self, p):
        '''
        获取要点击的元素
        :param j:
        :return:
        '''
        element = self.login_page.get_element_ViewGroupC()
        return element[p].click()

    def click_elments_img(self, n):
        '''
        获取要点击的图片
        :return:
        '''
        image_element = self.login_page.get_element_imageC()
        return image_element[n].click()

    def edit_elements(self, z, q):
        '''
        获取可编辑的元素
        '''
        time.sleep(1)
        eidt_element = self.login_page.get_element_edit()
        return eidt_element[z].send_keys(q)

    def get_fail_tost(self, message):
        '''
        获取tost，返回信息
        :param message:
        :return:
        '''
        tost_element = self.login_page.get_tost_elementC(message)
        print(tost_element)
        if tost_element:
            return True
        else:
            return False

if __name__ == '__main__':
    pass